<template>
  <div class="manage-container">
    <div class="search-wrapper">
      <el-form :inline="true" class="demo-form-inline">
        <el-row :gutter="20">
          <el-col :md="6" :sm="24">
            <el-form-item label="状态:">
              <el-select
                size="small"
                v-model="form.enable"
                placeholder="请选择"
              >
                <el-option label="全部" value=""></el-option>
                <el-option label="启用" :value="1"></el-option>
                <el-option label="禁用" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :md="6" :sm="24">
            <el-form-item label="关键词:">
              <el-input
                size="small"
                placeholder="请输入关键词搜索"
                v-model="form.keyword"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col
            :md="6"
            :sm="24"
            style="padding-top: 5px; box-sizing: border-box"
          >
            <el-button
              size="small"
              icon="el-icon-search"
              @click="listScreenInfo"
              >查询</el-button
            >
          </el-col>
          <el-col :md="6" :sm="24"> </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="screen-wrapper">
      <div class="box-screen">
        <div class="item-screen">
          <i class="el-icon-plus" @click="addScreenInfo"></i>
        </div>
        <div
          v-for="(data, index) in dataList"
          :key="index"
          :class="data.enable === 1 ? 'item-screen' : 'item-screen disable'"
        >
          <div class="screen-header">
            <div class="title">{{ data.name }}</div>
            <div class="sub-title">{{ data.width }} * {{ data.height }}</div>
          </div>
          <div class="screen-body">{{ data.remark }}</div>
          <div class="screen-footer">
            <span class="time">{{ data.createTime | filterTime }}</span>
            <span class="icon">
              <i class="el-icon-view" @click="viewScreenInfo(data.id)"></i>
              <i class="el-icon-edit" @click="editScreenInfo(data.id)"></i>
              <i class="el-icon-delete" @click="deleteScreenInfo(data.id)"></i>
            </span>
          </div>
        </div>
      </div>
    </div>
    <div class="page-wrapper">
      <el-pagination
        :current-page="pageObject.page"
        :page-sizes="[10, 20, 30, 40, 50]"
        :page-size="pageObject.size"
        layout="total, prev, pager, next, sizes"
        :total="pageObject.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { obtainScreenList, deleteScreenInfo } from "@/api";
import Moment from "moment";
import { v4 as uuidv4 } from "uuid";
export default {
  data() {
    return {
      form: {
        enable: "",
        keyword: "",
      },
      dataList: [],
      pageObject: {
        page: 1,
        size: 10,
        total: 0,
      },
    };
  },
  filters: {
    filterTime(time) {
      return Moment(time).format("YYYY-MM-DD HH:mm:ss");
    },
  },
  mounted() {
    this.listScreenInfo();
  },
  methods: {
    listScreenInfo() {
      let params = {
        page: this.pageObject.page,
        size: this.pageObject.size,
      };
      if (this.form.enable !== "") {
        params.enable = this.form.enable;
      }
      if (this.form.keyword) {
        params.keyword = this.form.keyword;
      }
      obtainScreenList(params).then((response) => {
        const data = response.data;
        this.dataList = data.list;
        this.pageObject.total = data.total;
      });
    },
    handleCurrentChange(page) {
      this.pageObject.page = page;
      this.listScreenInfo();
    },
    handleSizeChange(size) {
      this.pageObject.size = size;
      this.listScreenInfo();
    },
    addScreenInfo() {
      let router = this.$router.resolve({
        name: "designer",
        params: {
          id: uuidv4(),
        },
      });
      window.open(router.href, "_blank");
    },
    viewScreenInfo(screenId) {
      let router = this.$router.resolve({
        name: "views",
        params: {
          id: screenId,
        },
      });
      window.open(router.href, "_blank");
    },
    editScreenInfo(screenId) {
      let router = this.$router.resolve({
        name: "designer",
        params: {
          id: screenId,
        },
      });
      window.open(router.href, "_blank");
    },
    deleteScreenInfo(screenId) {
      this.$confirm("是否确认删除该大屏信息？", "提示", {
        type: "warning",
      })
        .then(() => {
          deleteScreenInfo(screenId).then(() => {
            this.$message({
              showClose: true,
              message: "删除成功",
              type: "success",
            });
            this.listScreenInfo();
          });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="stylus">
.manage-container {
  height: 100%;
  padding: 20px;
  box-sizing: border-box;

  .search-wrapper {
    .el-form {
      .el-row {
        .el-col {
          .el-form-item {
            display: flex;

            .el-form-item__label {
            }

            .el-form-item__content {
              flex-grow: 1;

              .el-select {
                width: 100%;
              }
            }
          }
        }
      }
    }
  }

  .screen-wrapper {
    .box-screen {
      .item-screen {
        width: 250px;
        height: 200px;
        padding: 10px;
        border: 1px solid #6ec91b;
        box-sizing: border-box;
        display: inline-block;
        vertical-align: top;
        margin: 0 10px 10px 0;

        &:first-child {
          line-height: 200px;
          text-align: center;
          border: 1px solid #40a9ff;

          i {
            font-size: 50px;
            color: #40a9ff;
            cursor: pointer;
          }
        }

        &.disable {
          border: 1px solid #d52e22;
        }

        .screen-header {
          height: 80px;

          .title {
            height: 40px;
            line-height: 40px;
            font-weight: bold;
            font-size: 24px;
            text-align: center;
            color: #2c2925;
          }

          .sub-title {
            height: 30px;
            margin-top: 10px;
            line-height: 30px;
            font-size: 16px;
            text-align: center;
            color: #b9b0a5;
          }
        }

        .screen-body {
          height: 50px;
          margin-top: 20px;
          font-size: 12px;
          color: #7e7c7c;
        }

        .screen-footer {
          margin-top: 5px;

          .time {
            display: inline-block;
            float: left;
            font-size: 10px;
            vertical-align: top;
            padding-top: 1px;
          }

          .icon {
            display: inline-block;
            vertical-align: top;
            text-align: right;
            float: right;
            font-size: 14px;

            i {
              cursor: pointer;
              margin-left: 8px;
              margin-right: 8px;

              &:hover {
                color: #40a9ff;
              }
            }
          }
        }
      }
    }
  }

  .page-wrapper {
    height: 50px;
    margin-top: 20px;
    text-align: right;

    .el-pagination {
      .btn-prev {
        padding-right: 5px;
      }

      .btn-next {
        padding-left: 5px;
      }

      button {
        min-width: 32px !important;
        height: 32px;
        border: 1px solid #C0C4CC;
        border-radius: 4px;

        &.active {
          color: #40a9ff;
          border: 1px solid #40a9ff;
        }

        &:hover {
          color: #40a9ff;
          border: 1px solid #40a9ff;
        }

        &:disabled {
          &:hover {
            color: #C0C4CC;
            border: 1px solid #C0C4CC;
          }
        }
      }

      .el-pager {
        .number {
          min-width: 32px;
          height: 32px;
          margin-left: 10px;
          border: 1px solid #C0C4CC;
          border-radius: 4px;
          font-weight: normal;

          &.active {
            color: #40a9ff;
            border: 1px solid #40a9ff;
          }

          &:hover {
            color: #40a9ff;
            border: 1px solid #40a9ff;
          }

          &:last-child {
            margin-right: 10px;
          }
        }
      }

      .el-pagination__sizes {
        height: 33px;
        margin-left: 5px;

        .el-select {
          height: 100%;

          .el-input {
            height: 100%;

            .el-input__inner {
              height: 100%;
              border-radius: 4px;
            }
          }
        }
      }
    }
  }
}
</style>
